package com.living.player.ui.recently.adapter;

import android.graphics.Color;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.living.Constant;
import com.living.R;
import com.md.basedpc.persistence.PHSPUtil;
import com.md.network.api.Audio;

import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/***
 * 下载适配器
 */
public class RecentlyAudioAdapter extends BaseQuickAdapter<Audio, BaseViewHolder> {
    boolean isSelfCreated;
    boolean isInEdite = false;
    private Map<String, Audio> mapSel = new ConcurrentHashMap<>();

    public RecentlyAudioAdapter(boolean isInEdite, boolean isSelfCreated,Map<String, Audio> mapSel) {
        super(R.layout.item_downloaded_task);
        this.isInEdite = isInEdite;
        this.mapSel = mapSel;
        this.isSelfCreated = isSelfCreated;
    }

    public RecentlyAudioAdapter(boolean isInEdite, Map<String, Audio> mapSel) {
        super(R.layout.item_downloaded_task);
        this.isInEdite = isInEdite;
        this.mapSel = mapSel;
    }

    public RecentlyAudioAdapter() {
        super(R.layout.item_downloaded_task);
        addChildClickViewIds(R.id.task_action_more);
    }

    @NotNull
    @Override
    protected BaseViewHolder onCreateDefViewHolder(@NotNull ViewGroup parent, int viewType) {
        BaseViewHolder holder = super.onCreateDefViewHolder(parent, viewType);
        return holder;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, Audio model) {
        holder.setText(R.id.task_name_tv, model.getId() + "  " + model.getName());
        holder.setText(R.id.task_status_tv, model.getAuthor() + "  《" + model.getAlbumName() + "》");
        holder.setGone(R.id.task_action_select, true);
        if (isInEdite) {
            holder.setGone(R.id.task_action_select, false);
            if (isSelfCreated){
                holder.setGone(R.id.task_action_more, false);
                holder.setImageResource(R.id.task_action_more,R.drawable.icon_self_item_more);
            }else {
                holder.setGone(R.id.task_action_more, true);
            }
            if (mapSel.containsKey(model.getId())) {
                holder.setImageResource(R.id.task_action_select, R.drawable.icon_download_selected);
            } else {
                holder.setImageResource(R.id.task_action_select, R.drawable.icon_download_select);
            }
        } else {
            holder.setGone(R.id.task_action_select, true);
            holder.setGone(R.id.task_action_more, false);
        }


        if (PHSPUtil.getInstance().getString(Constant.player_recent_audio_id, "").equals(model.getId())) {
            holder.setTextColor(R.id.task_name_tv, Color.parseColor("#12C286"));
            holder.setTextColor(R.id.task_status_tv, Color.parseColor("#12C286"));
        } else {
            holder.setTextColor(R.id.task_name_tv, Color.parseColor("#262626"));
            holder.setTextColor(R.id.task_status_tv, Color.parseColor("#757575"));
        }

    }


}
